using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Presenters;
using Dominio;

public partial class ReleaseDetails : AbstractView
{
    private ReleaseDetailsPresenter presenter;
    private String statePage =  "new";

    public ReleaseDetails()
    {
        presenter = new ReleaseDetailsPresenter();
    }     
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack) return;
        this.LogedIn();
        statePage = Request.QueryString.Get("statePage");

        foreach (Control ctrl in Master.FindControl("ContentPlaceHolder1").Controls)
        {
            if (ctrl is TextBox || ctrl is DropDownList)
            {
                ctrl.Visible = statePage.Equals("new") || statePage.Equals("editable");
            }
            if (ctrl is Label && ctrl.ID.Contains("text"))
            {
                ctrl.Visible = statePage.Equals("info");
            }
        }

        if (Request.QueryString.Get("ReleaseId") != "null") 
        {
            Release release = presenter.getReleaseById(int.Parse(Request.QueryString.Get("ReleaseId")));

            Idtxt.Text = release.Id.ToString();

            closeDate.Text = release.CloseDate.ToString();
            closeDatetext.Text = release.CloseDate.ToString();

            creationDate.Text = release.CreationDate.ToString();
            creationDatetext.Text = release.CreationDate.ToString();

            descripttxt.Value = release.Description;
            descripttext.Text = release.Description;
        }
    }

    protected void Update_Click(object sender, EventArgs e)
    {
       presenter.updateRelease(int.Parse(Idtxt.Text), closeDate.Text, creationDate.Text, descripttxt.Value,versiontxt.Text, urltxt.Text, (TestingManager)Session["user"]);
    }
}
